package com.bank.rabbitmq.controller;

import com.bank.rabbitmq.pojo.MyMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SendController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @GetMapping("/send")
    public String send(String msg){
        MyMessage myMessage = new MyMessage();
        myMessage.setMsg(msg);
        //channel.basicPublish  bytes
        //想把msg数据 作为消息 发送到queue_demo队列 通过 direct_demo交换机 绑定 demo_rk
        rabbitTemplate.convertAndSend("direct_demo","demo_rk",myMessage);
        return "success";
    }
}
